home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / tools / developer-tools / c-tools / c_examples / status / status.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-02  |  2.8 KB  |  117 lines

  1. //////////////////////////////////////////////////////////////////////////////
  2. // status.cpp
  3. //
  4. // Jeffry A Worth
  5. // November 10, 1995
  6. //////////////////////////////////////////////////////////////////////////////
  7.  
  8. //////////////////////////////////////////////////////////////////////////////
  9. // INCLUDES
  10. #include "aframe:include/status.hpp"
  11. #include "aframe:include/rastport.hpp"
  12.  
  13. //////////////////////////////////////////////////////////////////////////////
  14. //
  15.  
  16. AFStatus::AFStatus()
  17. {
  18.   m_text=NULL;
  19.   m_percent=0;
  20. }
  21.  
  22. AFStatus::~AFStatus()
  23. {
  24.   DestroyObject();
  25. }
  26.  
  27. void AFStatus::DestroyObject()
  28. {
  29.   AFGadget::DestroyObject();
  30.   if(m_text) {
  31.     delete m_text;
  32.     m_text=NULL;
  33.   }
  34. }
  35.  
  36. void AFStatus::Create(AFWindow* pwindow, AFRect *rect, ULONG id, UBYTE penDone, UBYTE penToGo)
  37. {
  38.   AFRastPort rp(pwindow);
  39.   char string[10];
  40.  
  41.   // Create the gadget
  42.   AFGadget::Create(pwindow,rect,id);
  43.  
  44.   // Create string for the text
  45.   sprintf(string,"%d%%",m_percent);
  46.   m_text = new char[strlen(string)+1];
  47.   strcpy(m_text,string);
  48.  
  49.   // Set Pens
  50.   m_penDone = penDone;
  51.   m_penToGo = penToGo;
  52.  
  53.   // Build Images
  54.   m_Done.NextImage=&m_ToGo;
  55.   m_ToGo.NextImage=NULL;
  56.   BuildImages(); 
  57.  
  58.   // Fill IntuiText Structure
  59.   m_IntuiText.FrontPen = 1;
  60.   m_IntuiText.DrawMode = JAM1;
  61.   m_IntuiText.LeftEdge = 5;
  62.   m_IntuiText.TopEdge = 5;
  63.   m_IntuiText.ITextFont = NULL;
  64.   m_IntuiText.LeftEdge = (m_pgadget->Width-rp.TextLength(m_text,strlen(m_text)))/2;
  65.   m_IntuiText.IText = (UBYTE*)m_text;
  66.   m_IntuiText.NextText = NULL;
  67.  
  68.   // Attach IntuiText Struct and Border Struct to gadget Struct
  69.   m_pgadget->GadgetText = &m_IntuiText;
  70.   m_pgadget->GadgetRender = &m_Done;
  71.   m_pgadget->Flags = GFLG_GADGIMAGE|GFLG_GADGHNONE;
  72. }
  73.  
  74. void AFStatus::BuildImages()
  75. {
  76.   // Fill Done Image Struct
  77.   m_Done.LeftEdge = m_Done.TopEdge = 0;
  78.   m_Done.Width=m_percent*m_pgadget->Width/100;
  79.   m_Done.Height=m_pgadget->Height;
  80.   m_Done.Depth=4;
  81.   m_Done.ImageData=NULL;
  82.   m_Done.PlanePick=NULL;
  83.   m_Done.PlaneOnOff=m_penDone;
  84.  
  85.   // Fill ToGo Image Struct
  86.   m_ToGo.TopEdge = 0;
  87.   m_ToGo.LeftEdge=m_percent*m_pgadget->Width/100;
  88.   m_ToGo.Width=m_pgadget->Width-m_ToGo.LeftEdge;
  89.   m_ToGo.Height=m_pgadget->Height;
  90.   m_ToGo.Depth=4;
  91.   m_ToGo.ImageData=NULL;
  92.   m_ToGo.PlanePick=NULL;
  93.   m_ToGo.PlaneOnOff=m_penToGo;
  94. }
  95.  
  96. void AFStatus::SetStatus(int percent)
  97. {
  98.   AFRastPort rp(m_pwindow);
  99.   char string[10];
  100.   
  101.   // Rebuild Images
  102.   m_percent=percent;
  103.   BuildImages();
  104.  
  105.   // Build Text String
  106.   m_IntuiText.IText = NULL;
  107.   if(m_text) delete m_text;
  108.   sprintf(string,"%d%%",m_percent);
  109.   m_text = new char[strlen(string)+1];
  110.   strcpy(m_text,string);
  111.   m_IntuiText.LeftEdge = (m_pgadget->Width-rp.TextLength(m_text,strlen(m_text)))/2;
  112.   m_IntuiText.IText = (UBYTE*)m_text;
  113.  
  114.   // Update the gadget
  115.   RefreshGList((struct Gadget*)m_pgadget, m_pwindow->m_pWindow, (struct Requester*)NULL, 1);
  116. }
  117.